package com.zimmur.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.druid.util.StringUtils;
import com.sun.org.apache.xpath.internal.operations.And;
import com.zimmur.common.AppModuleEnum;
import com.zimmur.common.IDWorkFactory;
import com.zimmur.common.PointConvert;
import com.zimmur.common.ReturnJsonEntity;
import com.zimmur.common.StatusCodeEnum;
import com.zimmur.model.account.CouponDetail;
import com.zimmur.model.account.GoodsUser;
import com.zimmur.model.account.PointLog;
import com.zimmur.model.account.PointLogParameter;
import com.zimmur.model.account.User;
import com.zimmur.model.account.UserAddress;
import com.zimmur.model.account.UserAdvice;
import com.zimmur.model.account.UserApply;
import com.zimmur.model.account.UserMessage;
import com.zimmur.model.account.UserNewMessage;
import com.zimmur.model.account.UserSizeInfo;
import com.zimmur.model.account.VerifyMobile;
import com.zimmur.model.account.view.CouponView;
import com.zimmur.model.account.view.LogView;
import com.zimmur.model.account.view.UserMessageView;
import com.zimmur.model.goods.OrderServiceParam;
import com.zimmur.model.order.Order;
import com.zimmur.model.order.OrderDetail;
import com.zimmur.model.order.OrderService;
import com.zimmur.model.order.view.CustomerServiceView;
import com.zimmur.model.order.view.OrderParameter;
import com.zimmur.service.IUserService;
import com.zimmur.service.IVerifyMobileService;
import com.zimmur.service.RedisCacheUtil;
import com.zimmur.service.account.ICouponService;
import com.zimmur.service.account.IPointLogService;
import com.zimmur.service.account.IPrepaidLogService;
import com.zimmur.service.account.IUserAddressService;
import com.zimmur.service.account.IUserAdviceService;
import com.zimmur.service.account.IUserApplyService;
import com.zimmur.service.account.IUserMessageService;
import com.zimmur.service.account.IUserNewMessageService;
import com.zimmur.service.account.IUserSizeInfoService;
import com.zimmur.service.account.IUserjeLogService;
import com.zimmur.service.goods.IGoodsSizeService;
import com.zimmur.service.order.IOrderDetailService;
import com.zimmur.service.order.IOrderService;
import com.zimmur.service.order.IOrderServiceDetailService;
import com.zimmur.service.order.IOrderServiceImageService;
import com.zimmur.service.order.IOrderServiceService;
import com.zimmur.tenpay.util.MD5;
import com.zimmur.tools.DateUtils;
import com.zimmur.tools.PageUtil;
import com.zimmur.tools.PublicKey;

@RestController
@RequestMapping("/restful/usercenter")  
public class UserCenterController extends BaseController{
	private static Logger log = LoggerFactory.getLogger(UserCenterController.class);
	
	@Resource
	private IUserAddressService userAddressService;
	@Resource
	private IUserMessageService userMessageService;
	@Resource
	private IUserSizeInfoService userSizeInfoService;
	@Resource 
	private IUserApplyService userApplyService;
	@Resource
	private IUserService userService;
	@Resource(name="orderServiceImpl")
	private IOrderService orderService;
	@Resource(name="orderServiceServiceImpl")
	private IOrderServiceService orderServiceService;
	@Resource(name="orderServiceDetailServiceImpl")
	private IOrderServiceDetailService orderServiceDetailService;
	@Resource
	private IOrderDetailService orderDetailService;
	@Resource
	private IOrderServiceImageService orderServiceImageService;
	@Resource
	private IPointLogService pointLogService;
	@Resource
	private IUserjeLogService userjeLogService;
	
	@Resource(name="verifyMobileService")
	private IVerifyMobileService verifyMobileService;
	@Resource
	private IPrepaidLogService prepaidLogService;
	@Resource
	private IUserAdviceService userAdviceService;
	@Resource
	private ICouponService couponService;
	@Resource
	private IGoodsSizeService goodsSizeService;
	
	
	 @Value("#{spingMvcProperties['public.key']}")
	private String publicKey;
	@Resource
	private RedisCacheUtil<String> redisCacheUtil;
	
	@Resource
	private IUserNewMessageService userNewMessageService;
	@Value("#{spingMvcProperties['System.GuestId']}")
	private String guessUserId;
	/**
	 * 5.2.3获取用户信息
	 * @param request
	 * @return 
	 */
	@RequestMapping(value="/userinfo",method=RequestMethod.GET)
	public ReturnJsonEntity userInfo(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum statusCodeEnum = StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				statusCodeEnum=StatusCodeEnum.CODE100200;
				entity.setCode(statusCodeEnum.getCode());
				entity.setMsg(statusCodeEnum.getMsg());
				return entity;
			}
			User user = userService.getUserInfoByUserId(userId);
			if(user != null){
				user.setMessageNum(userNewMessageService.selectNoReadMessageNum(userId));
        		//获取公钥
        		String Key=PublicKey.getKey(redisCacheUtil, publicKey);
        		user.setPublicKey(Key);
				
				entity.setData(user);	
				statusCodeEnum = StatusCodeEnum.CODE000000;
			}
		}catch(Exception e){
			log.error(e.getMessage());
			statusCodeEnum = StatusCodeEnum.CODE100000;
		}
		
		entity.setCode(statusCodeEnum.getCode());
		entity.setMsg(statusCodeEnum.getMsg());
		return entity;
	}
	/**
	 * 5.7.1.0 修改用户信息
	 * @param request
	 * @return 
	 */
	@RequestMapping(value="/userinfoupdate",method=RequestMethod.POST)
	public ReturnJsonEntity userinfoUpdate(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum statusCodeEnum = StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				statusCodeEnum=StatusCodeEnum.CODE100200;
				entity.setCode(statusCodeEnum.getCode());
				entity.setMsg(statusCodeEnum.getMsg());
				return entity;
			}
			String userName = getParam("userName", "");
			Integer gender = getIntParam("gender");
			String birthday = getParam("birthday");
			String email = getParam("email");
			String userPwd = getParam("userPwd");
			String newUserPwd = getParam("newUserPwd");

			User user = new User();
			user.setUserId(userId+"");
			//修改用户名称
			if(!userName.equals("")){
				//校验用户名称是否重复
				User checkUser = userService.getUserInfoByUserName(userName, "");
				if(checkUser != null&&!checkUser.getUserId().equals(userId+"")){
					statusCodeEnum = StatusCodeEnum.CODE200203;
					entity.setCode(statusCodeEnum.getCode());
					entity.setMsg(statusCodeEnum.getMsg());
					return entity;
				}
				user.setUserName(userName);
			}
			//性别
			if(!gender.equals("")){
				user.setGender(gender);
			}
			//生日
			if(!birthday.equals("")){
				user.setBirthday(birthday);
			}
			//邮箱
			if(!email.equals("")){
				user.setEmail(email);
			}
			//修改密码
			if(!(newUserPwd.equals("")||userPwd.equals(""))){
					user.setUserPwd(MD5.MD5Encode(newUserPwd));
			}
			//只有旧密码一致才能修改个人信息
			User user1 = userService.getUserInfoByUserId(userId);
			if(user1!=null){
				if(!MD5.MD5Encode(userPwd).equals(user1.getUserPwd())){
					statusCodeEnum = StatusCodeEnum.CODE200205;
					entity.setCode(statusCodeEnum.getCode());
					entity.setMsg(statusCodeEnum.getMsg());
					return entity;
				}
			}
			Integer resut = userService.updateUserinfo(user);			
			if(resut > 0){
				statusCodeEnum = StatusCodeEnum.CODE000000;
			}
		}catch(Exception e){
			log.error(e.getMessage());
			statusCodeEnum = StatusCodeEnum.CODE100000;
		}
		entity.setCode(statusCodeEnum.getCode());
		entity.setMsg(statusCodeEnum.getMsg());
		return entity;
	}
	//获取默认送货地址
	@RequestMapping(value="/getdefaultaddress", method= RequestMethod.GET)
	public ReturnJsonEntity getDefaultAddress(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		long userId = getTokenUserId();
		//游客身份验证
		if(isGuess(guessUserId)){
			status=StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		try{
			 List<UserAddress> list = userAddressService.selectByUserId(userId);
			 if(!list.isEmpty()){
				 entity.setData(list.get(0));
			 }
			 status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	
	@RequestMapping(value="/address", method= RequestMethod.GET)
	public ReturnJsonEntity userAddressList(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		long userId = getTokenUserId();
		//游客身份验证
		if(isGuess(guessUserId)){
			status=StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		try{
			 List<UserAddress> list = userAddressService.selectByUserId(userId);
			 if(!list.isEmpty()){
				 entity.setData(list);
			 }else{
				 entity.setData(new ArrayList<>());
			 }
			 status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
			entity.setData(new ArrayList<>());
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	//个人地址增加,修改
	@RequestMapping(value="/address", method= RequestMethod.POST)
	public ReturnJsonEntity userAddressEdit(UserAddress userAddress){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			if(!userAddress.getProvince().equals("") && !userAddress.getCity().equals("") 
					&& !userAddress.getStreet().equals("")&&!userAddress.getPostCode().equals("")){
				String addressId = userAddress.getAddressId();
				userAddress.setUserId(userId);
				userAddress.setCreateDate(DateUtils.getNowUnixTime());
				//增加或修改
				if(addressId!=null&&!addressId.equals("")&&!addressId.equals("0")){					
					userAddressService.update(userAddress);
				}else{
					long addreId = IDWorkFactory.getID(AppModuleEnum.Account);
					userAddress.setAddressId(addreId+"");
					userAddressService.insert(userAddress);
				}
				if(userAddress.getIsDefault()==1){
					userAddressService.setDefaultAddress(userId,Long.parseLong(addressId) );
				}
				status=StatusCodeEnum.CODE000000;
				entity.setData(userAddress);
			}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: getAddressInfo</p>
	* <p>Description: 查询地址信息</p>
	* @param userAddress
	* @return
	 */
	@RequestMapping(value="/getaddressinfo", method= RequestMethod.GET)
	public ReturnJsonEntity getAddressInfo(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		UserAddress userAddress = null;
		try{
			long addressId = getLongParam("addressId");
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
				//查询地址信息
				if(addressId>0){					
					userAddress = userAddressService.selectById(addressId);
				}
				if(userAddress!=null&&userAddress.getUserId()==userId){
					status=StatusCodeEnum.CODE000000;
					entity.setData(userAddress);
				}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: userAddressDel</p>
	* <p>Description: 删除地址信息</p>
	* @return
	 */
	@RequestMapping(value="/deladdress",method = RequestMethod.POST)
	public ReturnJsonEntity userAddressDel(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		long userId =getTokenUserId();
		//游客身份验证
		if(isGuess(guessUserId)){
			status=StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		try{
			long addressId = getLongParam("addressId");
			boolean bRet = userAddressService.delete(addressId);
			if(bRet)
				status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	//设置默认收货地址
	@RequestMapping(value="/defaultaddress",method = RequestMethod.POST)
	public ReturnJsonEntity userAddressDefault(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			long addressId = getLongParam("addressId");
			boolean bRet = userAddressService.setDefaultAddress(userId, addressId);
			if(bRet)
				status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	
	// 消息中心 主页
	@RequestMapping(value="/messageIndex",method = RequestMethod.GET)
	public ReturnJsonEntity messageIndex(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			Map<String,UserNewMessage> userNewMessages=userNewMessageService.selectMessageByUserId(userId);
			entity.setData(userNewMessages);
			status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
			entity.setData(new  ArrayList<>());
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	// 通知，闪创消息 分页
	@RequestMapping(value="/noticeMessagePage",method = RequestMethod.GET)
	public ReturnJsonEntity noticeMessagePage(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try {
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			int pageNow = getParam("pageNow",1);
			String code = getParam("code");
			PageUtil<UserMessageView> userMessages=null;
			if("notify".equals(code) || "organization".equals(code)){
				userMessages=userMessageService.selectMessageByUserIdAndCategoryCode(userId,code,pageNow);
			}else{
				userMessages=new PageUtil<>();
			}
			
			entity.setData(userMessages);
			status = StatusCodeEnum.CODE000000;
		} catch (Exception er) {
			log.error(er.getMessage(),er);
			status = StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	//积分抵扣支付费用计算
	@RequestMapping(value="/calcpointtofee",method=RequestMethod.GET)
	public ReturnJsonEntity calcPointConvertFee(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			int point = getIntParam("point");
			if(point>0 ){
				//long userId = getTokenUserId();
				double je = PointConvert.pointToJe(point);
				Map<String, Object> map = new HashMap<>();
				map.put("fee", je);
				entity.setData(map);
				status=StatusCodeEnum.CODE000000;
			}
			
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 5.7.1.11	我的积分明细
	 * @return
	 */
	@RequestMapping(value="/loglist",method=RequestMethod.GET)
	public ReturnJsonEntity myPointOrJelogList(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(String.valueOf(userId).equals(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			int pageNow = getIntParam("pageNow");
			//1=积分 2=余额
			int flag = getIntParam("flag");
			PointLogParameter parameter =new PointLogParameter();
			if(pageNow == 0){
				pageNow=1;
			}
			parameter.setCurrentPage(pageNow);
			
			parameter.setUserId(userId);
			
			int totalRecord = 0;
			
			if(flag == 1){
				PageUtil<PointLog> pageUtil = new PageUtil<>();
				parameter.setPageSize(pageUtil.getPageSize());
				List<PointLog> logList = new ArrayList<PointLog>();
				totalRecord = pointLogService.selectPageListByUserIdCount(parameter);
				if(totalRecord>0){
					pageUtil.setTotalRecord(totalRecord);
					parameter.setRowsCount(totalRecord);
					//我的积分日志
					logList = pointLogService.selectPageListByUserId(parameter);
					if(!logList.isEmpty()){
						for (PointLog log : logList) {
							log.setCreateTime(DateUtils.getUnixTimeToDefineFormat(log.getEventDate()));
						}
					}
					
				}
				pageUtil.setItemList(logList);
				entity.setData(pageUtil);
			}else{
				PageUtil<LogView> pageUtil = new PageUtil<>();
				parameter.setPageSize(pageUtil.getPageSize());
				List<LogView> logList = new ArrayList<LogView>();
				totalRecord = userjeLogService.selectPageListCount(parameter);
				if(totalRecord>0){
					pageUtil.setTotalRecord(totalRecord);
					parameter.setRowsCount(totalRecord);
					//我的充值日志
					logList = userjeLogService.selectPageListByUserId(parameter);
					
					if(!logList.isEmpty()){
						for (LogView log : logList) {
							log.setCreateTime(DateUtils.getUnixTimeToDefineFormat(log.getEventDate()));
						}
					}
				}
				pageUtil.setItemList(logList);
				entity.setData(pageUtil);
			}
			
			status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 5.7.1.12	我的尺码
	 * @return
	 */
	@RequestMapping(value="/sizelist",method=RequestMethod.GET)
	public ReturnJsonEntity mySizelist(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(String.valueOf(userId).equals(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			int pageNow = getIntParam("pageNow");
			PageUtil<UserSizeInfo> page= userSizeInfoService.selectByUserIdPage(userId, pageNow);
			
			entity.setData(page);
			status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 5.7.1.13	添加/修改我的尺码
	 * @return
	 */
	@RequestMapping(value="/sizeinfo",method=RequestMethod.POST)
	public ReturnJsonEntity sizeinfo(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//获取当前时间，转为INT存储
	        Integer timeDate =DateUtils.getUnixTimeByDate(DateUtils.getNow());
	        long recId = getLongParam("recId");
			long userId = getTokenUserId();
			String title = getParam("title");
			Integer xiongweiSize = getIntParam("xiongweiSize");
			Integer yaoweiSize = getIntParam("yaoweiSize");
			Integer tunweiSize = getIntParam("tunweiSize");
			Integer jianweiSize = getIntParam("jianweiSize");
			Integer jingweiSize = getIntParam("jingweiSize");
			Integer shengaoSize = getIntParam("shengaoSize");
			
			UserSizeInfo userSizeInfo = new UserSizeInfo();
			userSizeInfo.setRecId(recId);
			userSizeInfo.setUserId(userId);
			userSizeInfo.setTitle(title);
			userSizeInfo.setXiongweiSize(xiongweiSize);
			userSizeInfo.setYaoweiSize(yaoweiSize);
			userSizeInfo.setTunweiSize(tunweiSize);
			userSizeInfo.setJianweiSize(jianweiSize);
			userSizeInfo.setJingweiSize(jingweiSize);
			userSizeInfo.setShengaoSize(shengaoSize);
			userSizeInfo.setCreateDate(timeDate);
			//按尺码ID查找，true修改,false添加
//			UserSizeInfo userSizeInfo1 = userSizeInfoService.selectByPrimaryKey(recId);
			Integer resut=0;
			if(recId > 0){
				//修改
				resut = userSizeInfoService.updateByPrimaryKeySelective(userSizeInfo);
			}else{
				//添加
				userSizeInfo.setRecId(IDWorkFactory.getID(AppModuleEnum.UserCenter));
				resut = userSizeInfoService.insertSelective(userSizeInfo);
			}
			if(resut > 0){
				status=StatusCodeEnum.CODE000000;
			}else{
				status=StatusCodeEnum.CODE100000;
			}			
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 测试接口
	 * 发送消息   
	 * @return
	 */
	@RequestMapping(value="/sendmessage",method = RequestMethod.POST)
	public ReturnJsonEntity sendMessage(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			long toUserId = getLongParam("toUserId");
			String strMessage = getParam("message");
			String title=getParam("title");
			String categortCode=getParam("code");
			//int moduleId = Integer.parseInt(AppModuleEnum.Account.getModuleId());
			
			if(!strMessage.equals("")){
				UserMessage message = new UserMessage();
				message.setMessageId(IDWorkFactory.getID(AppModuleEnum.UserMessage));
				message.setUserId(0L);
				message.setToUserId(toUserId);
				message.setMsgType("text");
				message.setCategoryCode(categortCode);
				message.setModuleId(30);
				message.setMsgTitle(title);
				message.setMsgContent(strMessage);
				message.setDataId("");
				message.setIsPush(0);
				message.setIsRead(0);
				message.setCreateDate(DateUtils.getNowUnixTime());
				
				if(userMessageService.addNewMessage(message)){
					status=StatusCodeEnum.CODE000000;
				}				
			}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 5.7.1.15	星客认证
	 * @return
	 */
	@RequestMapping(value="/authentication",method=RequestMethod.POST)
	public ReturnJsonEntity authentiCation(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			//获取当前时间，转为INT存储
	        Integer timeDate =DateUtils.getUnixTimeByDate(DateUtils.getNow());
			long userId = getTokenUserId();
			GoodsUser user = userService.selectByUserId(userId);
			String categoryCode = user.getCategoryCode();
			if(!categoryCode.equals("zk")){
				status = StatusCodeEnum.CODE700160;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			String name = getParam("name");
			String occupation = getParam("occupation");
			String card = getParam("card");
			String photo = getParam("photo");
			String birthday = getParam("birthday");
			Integer marryStatus = getIntParam("marryStatus");
			String educate = getParam("educate");
			String city = getParam("city");
			Integer xiongweiSize = getIntParam("xiongweiSize");
			Integer yaoweiSize = getIntParam("yaoweiSize");
			Integer tunweiSize = getIntParam("tunweiSize");
			Integer jianweiSize = getIntParam("jianweiSize");
			Integer jingweiSize = getIntParam("jingweiSize");
			Integer shengaoSize = getIntParam("shengaoSize");
			
			UserApply userApply = new UserApply();
			userApply.setApplyId(IDWorkFactory.getID(AppModuleEnum.UserCenter));
			userApply.setUserId(userId);
			userApply.setName(name);
			userApply.setOccupation(occupation);
			userApply.setCard(card);
			userApply.setPhoto(photo);
			userApply.setBirthday(birthday);
			userApply.setMarryStatus(marryStatus);
			userApply.setEducate(educate);
			userApply.setCity(city);
			userApply.setXiongweiSize(xiongweiSize);
			userApply.setYaoweiSize(yaoweiSize);
			userApply.setTunweiSize(tunweiSize);
			userApply.setJianweiSize(jianweiSize);
			userApply.setJingweiSize(jingweiSize);
			userApply.setShengaoSize(shengaoSize);
			userApply.setCreateDate(timeDate);
			userApply.setApplyStatus(0);
			userApply.setCheckStatus(0);						
			Integer resut = userApplyService.insertSelective(userApply);			
			if(resut > 0){
				status=StatusCodeEnum.CODE000000;
			}else{
				status=StatusCodeEnum.CODE100000;
			}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 安全中心（绑定）
	 * @param request
	 * @return 
	 */
	@RequestMapping(value="/bindings",method=RequestMethod.POST)
	public ReturnJsonEntity bindings(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum statusCodeEnum = StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				statusCodeEnum=StatusCodeEnum.CODE100200;
				entity.setCode(statusCodeEnum.getCode());
				entity.setMsg(statusCodeEnum.getMsg());
				return entity;
			}
			long userId = getTokenUserId();
			String wxOpenId = getParam("wxOpenId");
			String wbOpenId = getParam("wbOpenId");
			String qq = getParam("qq");
			User user = new User();
			
			user.setUserId(userId+"");
			//微博
			if(!wbOpenId.equals("")){
				user.setWbOpenId(wbOpenId);
			}
			//微信
			if(!wxOpenId.equals("")){
				user.setWxOpenId(wxOpenId);
			}
			//qq
			if(!qq.equals("")){
				user.setQq(qq);
			}
			Integer resut = userService.updateUserinfo(user);			
			if(resut > 0){
				statusCodeEnum = StatusCodeEnum.CODE000000;
			}
		}catch(Exception e){
			log.error(e.getMessage());
			statusCodeEnum = StatusCodeEnum.CODE100000;
		}
		entity.setCode(statusCodeEnum.getCode());
		entity.setMsg(statusCodeEnum.getMsg());
		return entity;
	}
	/**
	 * 5.7.1.14	安全中心（修改密码） 
	 * @return
	 */
	@RequestMapping(value="/modifypassword",method=RequestMethod.POST)
	public ReturnJsonEntity modifyPassword(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			//获取当前时间，转为INT存储
	        Integer timeDate =DateUtils.getNowUnixTime();
			long userId= getTokenUserId();
			String verifyCode = getParam("verifyCode", "");
			//修改帐号须手机验证
	        String userName = getParam("userName");
	        //修改密码需要手机验证
	        String newUserPwd = getParam("newUserPwd");
			String mobileNo = getParam("mobileNo", "");
			//修改手机号需要 密码 并验证			
			String userPwd = getParam("userPwd");
			//修改邮箱			
			String email = getParam("email");
			
			VerifyMobile verifyMobile = null;
			if(!"".equals(userName) || (!"".equals(mobileNo) && !verifyCode.equals("")) || !"".equals(newUserPwd) || !"".equals(email)){
				String userMobileNo = "";
				GoodsUser goodsUser = userService.selectByUserId(userId);
				if(goodsUser != null){
					userMobileNo = goodsUser.getMobileNo();
				}
				if(verifyCode.equals("") && verifyCode.length()!=4){
					status = StatusCodeEnum.CODE200201;
					entity.setCode(status.getCode());
					entity.setMsg(status.getMsg());
					return entity;
				}
				
				verifyMobile=verifyMobileService.getInfoByMobileAndCode(userMobileNo,verifyCode);
				if(verifyMobile == null){
					status = StatusCodeEnum.CODE200201;
					entity.setCode(status.getCode());
					entity.setMsg(status.getMsg());
					return entity;
				}
				verifyMobile.setIsverify(1);
				verifyMobile.setVerifydate(timeDate);
				
			}
			Integer resuts = 0;
			User user = new User();
			user.setUserId(userId+"");
			//修改帐号
			if(!userName.equals("")){
				//检查用户名重复
				User checkUser = userService.getUserInfoByUserName(userName, "");
				if(checkUser != null){
					status = StatusCodeEnum.CODE200203;
					entity.setCode(status.getCode());
					entity.setMsg(status.getMsg());
					return entity;
				}
				userService.delUserToken(userId+"");
				user.setUserName(userName);
				resuts = userService.updateUserinfo(user);
			}
			
			//邮箱
			if(!email.equals("")){
				user.setEmail(email);
				resuts = userService.updateUserinfo(user);
			}
			//修改密码
			if(!newUserPwd.equals("")){
				userService.delUserToken(userId+"");
				user.setUserPwd(newUserPwd);
				resuts = userService.updateUserinfo(user);
			}
			//修改手机号码
			if(!"".equals(mobileNo) && !"".equals(userPwd)){
				user.setMobileNo(mobileNo);
				//根据手机号查找是否有此 帐号
				Long userIdNew = userService.selectByUserNameAndMobileNo(user);
				if(userIdNew !=null && userIdNew > 0){
					status = StatusCodeEnum.CODE700143;
					entity.setCode(status.getCode());
					entity.setMsg(status.getMsg());
					return entity;
				}
				//修改手机号前 首先得 验证用户密码 是否正确
				User user1 = userService.getUserInfoByUserId(userId);
				if(user1 == null || !user1.getUserPwd().equals(userPwd)){
					status=StatusCodeEnum.CODE700141;
					entity.setCode(status.getCode());
					entity.setMsg(status.getMsg());
					return entity;
				}
				resuts = userService.updateUserinfo(user);
			}
			if(resuts > 0){
				//验证码处理
				if(verifyMobile != null){
					verifyMobileService.updateVerifyStatus(verifyMobile);
				}
				status = StatusCodeEnum.CODE000000;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
			}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
		}
		
		return entity;
	}
	/**
	 * 5.7.2.4	取消订单 
	 * @return
	 */
	@RequestMapping(value="/order/cancel",method=RequestMethod.POST)
	public ReturnJsonEntity cancelOrder(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//获取当前时间，转为INT存储
//	        Integer timeDate =DateUtils.getUnixTimeByDate(DateUtils.getNow());
	        String orderId = getParam("orderId");
	        String reasonText = getParam("reasonText");
			Order order = orderService.selectByOrderId(Long.parseLong(orderId));
			if(order!=null && "00".equals(order.getOderStatus())){
				order.setOderStatus("90");
				order.setOrderStatusText("订单取消");
				order.setReasonText(reasonText);
				Integer resut =orderService.updateByPrimaryKeySelective(order);
				if(resut > 0){
					try {
						if(order.getOrderType() !=null && order.getOrderType()!=3){
							List<OrderDetail> orderDetails=orderDetailService.selectByOrderId(Long.parseLong(orderId));
							if (!orderDetails.isEmpty()) {
								for (OrderDetail orderDetail : orderDetails) {
									if (orderDetail.getQuantity() > 0) {
										goodsSizeService.updateOccInventoryToInventory(Long.parseLong(orderDetail.getSizeCode()),
												orderDetail.getQuantity(),orderDetail.getOrderType());
									}
								}
							}
						}
					} catch (Exception e) {
						log.error(e.getMessage(),e);
					}
					try {
						
						Short iscoupon=order.getIsusedCoupon();
						if(iscoupon!=null && iscoupon == 1){
							List<CouponDetail> couponDetails=couponService.selectCouponByOrderId(Long.parseLong(orderId));
							
							if (couponDetails!=null) {
								for(CouponDetail couponDetail:couponDetails){
									couponDetail.setCouponState("2");
									couponService.updateCoupon(couponDetail);
									couponService.updateCouponStock(couponDetail.getCouponStockId(), 0, 0, -1);
								}
							}
						}
					} catch (Exception e) {
						log.error(e.getMessage(),e);
					}
					status=StatusCodeEnum.CODE000000;
				}else{
					status=StatusCodeEnum.CODE100000;
				}		
			}else{
				status=StatusCodeEnum.CODE100000;
			}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 5.7.2.3	签收订单 
	 * @return
	 */
	@RequestMapping(value="/order/sign",method=RequestMethod.POST)
	public ReturnJsonEntity sign(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			//获取当前时间，转为INT存储
//	        Integer timeDate =DateUtils.getUnixTimeByDate(DateUtils.getNow());
	        String orderId = getParam("orderId");
			Order order = new Order();
			order.setOrderId(orderId);			
			order.setOderStatus("30");
			order.setOrderStatusText("已完成");
			order.setReceiptStatus(1);
//			order.setAftermarketStatus(3);
			Integer resut =orderService.updateByPrimaryKeySelective(order);
			if(resut > 0){
				status=StatusCodeEnum.CODE000000;
			}else{
				status=StatusCodeEnum.CODE100000;
			}		
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: getCustomerServiceList</p>
	* <p>Description: 查询我的售后服务单列表</p>
	* @return
	 */
	@RequestMapping(value="/customerservice/servicelist",method=RequestMethod.GET)
	public ReturnJsonEntity getCustomerServiceList(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			long userId = getTokenUserId();
			OrderServiceParam param = new OrderServiceParam();
			Integer pageNow = getIntParam("pageNow");//页码
			Integer pageSize = getParam("pageSize",10);//每页记录数
			String period = getParam("period");//1=最近三个月，2=最近半年,3=全部
			Integer serviceStatus = getParam("status",0);
			if(serviceStatus==10){
				serviceStatus =null;//即查询所有状态
			}
			String keyword = getParam("keyword");
			Integer time = 0;
			if(!StringUtils.isEmpty(period)&&period.equals("1")){
				time = DateUtils.getAfterdayUnixTime(-90);
			}else if(!StringUtils.isEmpty(period)&&period.equals("2")){
				time= DateUtils.getAfterdayUnixTime(-180);
			}else if(!StringUtils.isEmpty(period)&&period.equals("3")){
				time = null;
			}
			param.setKeyword(keyword);
			param.setPageIndex(pageNow);
			param.setPageSize(pageSize);
			param.setUserId(userId);
			param.setTime(time);
			param.setStatus(serviceStatus);
			PageUtil<CustomerServiceView> page=null;
			page= orderServiceService.queryServiceList(param);
			if(page==null){
				page=new PageUtil<>();
			}
			entity.setData(page);
			status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: applyCustomerService</p>
	* <p>Description: 申请售后服务</p>
	* @return
	 */
	@RequestMapping(value="/customerservice/applycustservice",method=RequestMethod.POST)
	public ReturnJsonEntity applyCustomerService(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		//游客身份验证
		if(isGuess(guessUserId)){
			status=StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		Long userId = getTokenUserId();
		String content = getParam("content");//内容描述
		String imageS = getParam("imageS");  //上传图片
		Long orderId = getLongParam("orderId");//订单id
		//一个订单能同时提交多个商品 申请（一对多）
		String orderDetailIdS = getParam("orderDetailIdS");	
		//售后服务类型
		Short isService = getShortParam("isService");//10=申请退款/20=申请换货/30=后台部分退款/40=申请退货
		String[] sArr=orderDetailIdS.split(",");
		try {
			if(isService==10){
				//1.查询当前订单明细判断是否已经申请过售后
				if(sArr[0] != "" && sArr.length > 0){
					for(String s:sArr){
						long orderDetailIdNew=Long.parseLong(s);
						
						OrderDetail orderDetail = orderDetailService.selectByOrderDetailID(orderDetailIdNew);
						if(orderDetail!=null&&orderDetail.getIsService()>0){
							status=StatusCodeEnum.CODE700402;
							entity.setCode(status.getCode());
							entity.setMsg(status.getMsg());
							return entity;
						}
					}
				}
			}
			//2.创建售后订单
			Long serviceId = orderServiceService.createOrderService(userId, content, imageS, orderId, orderDetailIdS, isService);
			if(serviceId>0){
				status=StatusCodeEnum.CODE000000;
				entity.setData(serviceId+"");
			}
		} catch (Exception e) {
			log.error(e.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: addExpressInfo</p>
	* <p>Description:添加售后服务快递信息 </p>
	* @return
	 */
	@RequestMapping(value="/customerservice/addShipData",method=RequestMethod.POST)
	public ReturnJsonEntity addExpressInfo(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		//游客身份验证
		if(isGuess(guessUserId)){
			status=StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		String shipCompany = getParam("shipCompany");//快递公司
		String shipNo = getParam("shipNo");//快递单号
		Long serviceId = getLongParam("serviceId");//退货单号
		Long userId = getTokenUserId();
		//
		try {
			Integer timeDate =DateUtils.getUnixTimeByDate(DateUtils.getNow());
			OrderService orderServiceModel = orderServiceService.queryCustServiceById(serviceId);
			String  userIdStr = orderServiceModel.getUserId();
			if (userIdStr.equals(userId+"")) {
				if(!shipNo.equals("") && !shipCompany.equals("")&&orderServiceModel!=null){
					if(orderServiceModel.getApplyStatus()==1){//审核通过让客户填写快递信息
						Short applyStatus = 9 ;//买家已发货
						orderServiceModel.setShipCompany(shipCompany);
						orderServiceModel.setShipNo(shipNo);
						orderServiceModel.setShipDate(timeDate);
						orderServiceModel.setApplyStatus(applyStatus);
						orderServiceModel.setApplyText("买家已发货");
						Short isFinish = 3;
						orderServiceModel.setIsFinish(isFinish);//isFinish状态:0=处理中 1=已完成 3=退货中
						Integer resutService =orderServiceService.updateByPrimaryKeySelective(orderServiceModel);
						if(resutService > 0){
							status=StatusCodeEnum.CODE000000;
						}else{
							status=StatusCodeEnum.CODE100000;
						}
					}
				}
			}else{
				status=StatusCodeEnum.CODE100000;
			}
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: getcustservicedetail</p>
	* <p>Description: 查询售后服务详情</p>
	* @return
	 */
	@RequestMapping(value="/customerservice/getcustservicedetail",method=RequestMethod.GET)
	public ReturnJsonEntity getcustservicedetail(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status = StatusCodeEnum.CODE100000;
		// 游客身份验证
		if (isGuess(guessUserId)) {
			status = StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		Long serviceId = getLongParam("serviceId");// 退货单号
		//
		OrderService orderService = orderServiceService.queryCustServiceDetail(serviceId);
		if (orderService != null) {
			status = StatusCodeEnum.CODE000000;
			entity.setData(orderService);
		} else {
			entity.setData(new OrderService());
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * <p>Title: canclecustservice</p>
	 * <p>Description: 取消售后</p>
	 * @return
	 */
	@RequestMapping(value="/customerservice/canclecustservice",method=RequestMethod.GET)
	public ReturnJsonEntity cancleCustService(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status = StatusCodeEnum.CODE100000;
		// 游客身份验证
		if (isGuess(guessUserId)) {
			status = StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		Long userId = getTokenUserId();
		Long serviceId = getLongParam("serviceId");// 退货单号
		Short applyStatus = 99;
		//
		OrderService orderService = orderServiceService.queryCustServiceById(serviceId);
		if (orderService != null) {
			String userIdStr = orderService.getUserId();
			if (userIdStr.equals(userId+"")) {
				if (orderService.getApplyStatus() == 0 || orderService.getApplyStatus() == 1) {
					orderService.setApplyStatus(applyStatus);
					orderService.setApplyText("售后取消");
					orderServiceService.updateByPrimaryKeySelective(orderService);
					status = StatusCodeEnum.CODE000000;
				} else {
					status = StatusCodeEnum.CODE700404;
				}
			} else {
				status = StatusCodeEnum.CODE100000;
			}
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: confirmCustService</p>
	* <p>Description:售后确认收货 </p>
	* @return
	 */
	@RequestMapping(value="/customerservice/confirmCustService",method=RequestMethod.GET)
	public ReturnJsonEntity confirmCustService(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status = StatusCodeEnum.CODE100000;
		// 游客身份验证
		if (isGuess(guessUserId)) {
			status = StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		Long userId = getTokenUserId();
		Long serviceId = getLongParam("serviceId");// 退货单号
		Short applyStatus = 8;
		//
		OrderService orderService = orderServiceService.queryCustServiceById(serviceId);
		if (orderService != null) {
			String userIdStr = orderService.getUserId();
			if (userIdStr.equals(userId+"")) {
				// 卖家已发货的状态才可以确认收货并完成售后
				if (orderService.getApplyStatus() == 4) {
					orderService.setApplyStatus(applyStatus);
					orderService.setApplyText("售后完成");
					orderServiceService.updateByPrimaryKeySelective(orderService);
					status = StatusCodeEnum.CODE000000;
				} else {
					status = StatusCodeEnum.CODE700405;
				}
			} else {
				status = StatusCodeEnum.CODE100000;
			}
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 5.7.2.1	我的订单列表
	 * @return
	 */
	@RequestMapping(value="/order/list",method=RequestMethod.GET)
	public ReturnJsonEntity orderList(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			long userId = getTokenUserId();
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			int pageNow = getIntParam("pageNow");
			String goodsTitle= getParam("goodsTitle");//商品标题
			/**
			 * 00=待付款/10=待发货、已发货/30=已完成/40=待退款/50=已退款/ 90=订单取消、超时未支付/99=所有状态
			 */
			String orderStatus= getParam("orderStatus");
			OrderParameter orderParameter = new OrderParameter(); 
			if(pageNow == 0){
				pageNow=1;
			}
			//查询所有状态的订单信息
			if(!StringUtils.isEmpty(orderStatus) && "99".equals(orderStatus)){
				orderStatus = "";
			}
			orderParameter.setUserId(userId);
			orderParameter.setPageNo(pageNow);
			orderParameter.setOrderStatus(orderStatus);
			orderParameter.setOrderType(1);//衣匠订单
			orderParameter.setGoodsTitle(goodsTitle);
			PageUtil<Order> page= orderService.selectByOderStatusList(orderParameter);
			
			entity.setData(page);
			status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: queryorderdetail</p>
	* <p>Description: 查询订单详情</p>
	* @return
	 */
	@RequestMapping(value="/order/orderdetail",method=RequestMethod.GET)
	public ReturnJsonEntity queryOrderDetail(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			Long userId  = getTokenUserId();
			Long orderId = getLongParam("orderId");
			Order order = orderService.selectByOrderDetailIdAndUserId(orderId, userId);
			if(order!=null){
				entity.setData(order);
				status=StatusCodeEnum.CODE000000;
			}else{
				entity.setData(new OrderDetail());
				status=StatusCodeEnum.CODE000000;
			}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 闪创订单列表
	 * @return
	 */
	@RequestMapping(value="/organizationOrder/list",method=RequestMethod.GET)
	public ReturnJsonEntity organizationOrderList(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			long userId = getTokenUserId();
			int pageNow = getIntParam("pageNow");
			String orderStatusList= getParam("orderStatus");
			
			OrderParameter orderParameter = new OrderParameter(); 
			if(pageNow == 0){
				pageNow=1;
			}
			orderParameter.setUserId(userId);
			orderParameter.setPageNo(pageNow);
			orderParameter.setOrderType(3);//闪创订单
			if("1".equals(orderStatusList)||"2".equals(orderStatusList) ||"3".equals(orderStatusList)){
				orderParameter.setOrderStatusList(orderStatusList);		
				PageUtil<Order> page= orderService.selectOrganizationOrder(orderParameter);
				entity.setData(page);
				status=StatusCodeEnum.CODE000000;
			}else{
				entity.setData(new ArrayList<>());
			}
			
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	 * 5.7.1.17意见建议
	 * @return
	 */
	@RequestMapping(value="/advice",method = RequestMethod.POST)
	public ReturnJsonEntity userAdvice(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		try{
			//游客身份验证
			if(isGuess(guessUserId)){
				status=StatusCodeEnum.CODE100200;
				entity.setCode(status.getCode());
				entity.setMsg(status.getMsg());
				return entity;
			}
			long userId = getTokenUserId();
			String content = getParam("content");
			String mobileNo = getParam("mobileNo");
			String email = getParam("email");
			if(!"".equals(content)){
				UserAdvice advice = new UserAdvice(userId,content,mobileNo,email);
				advice.setAdviceId(IDWorkFactory.getID(AppModuleEnum.Account));
				advice.setCreateDate(DateUtils.getNowUnixTime());
				
				if(userAdviceService.insert(advice)){
					status=StatusCodeEnum.CODE000000;
				}
			}
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: userCoupon</p>
	* <p>Description:查询用户可用的优惠券 </p>
	* @return
	 */
	@RequestMapping(value="/userCoupon",method = RequestMethod.POST)
	public ReturnJsonEntity userCoupon(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		// 游客身份验证
		if (String.valueOf(getTokenUserId()).equals(guessUserId)) {
			status = StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		try{
			long userId = getTokenUserId();
			int mininum=getIntParam("orderJe");
			/**
			 * 是否含折扣商品 0=不包含 1=包含
			 */
			int useByPercent=getIntParam("useByPercent");
			/**
			 * 是否含预售 0=不包含 1=包含
			 */
			int useByGoods=getIntParam("isPrepay");
			List<CouponView> couponDetails=couponService.selectByUserId(userId,mininum,useByPercent,useByGoods);
			entity.setData(couponDetails);
			status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: userAllCoupon</p>
	* <p>Description: 查询用户所有的优惠券</p>
	* @return
	 */
	@RequestMapping(value="/userAllCoupon",method = RequestMethod.GET)
	public ReturnJsonEntity userAllCoupon(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		// 游客身份验证
		if (String.valueOf(getTokenUserId()).equals(guessUserId)) {
			status = StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		try{
			long userId = getTokenUserId();
			List<CouponView> couponDetails=couponService.selectAllCouponByMobileNo(userId);
			entity.setData(couponDetails);
			status=StatusCodeEnum.CODE000000;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	/**
	* <p>Title: queryCouponbycode</p>
	* <p>Description: 通过优惠码查询优惠券</p>
	* @return
	 */
	@RequestMapping(value="/queryvalidcoupon",method = RequestMethod.GET)
	public ReturnJsonEntity queryValidCoupon(){
		ReturnJsonEntity entity = new ReturnJsonEntity();
		StatusCodeEnum status=StatusCodeEnum.CODE100000;
		// 游客身份验证
		if (String.valueOf(getTokenUserId()).equals(guessUserId)) {
			status = StatusCodeEnum.CODE100200;
			entity.setCode(status.getCode());
			entity.setMsg(status.getMsg());
			return entity;
		}
		try{
			Long userId = getTokenUserId();
			Integer orderJe = getParam("orderJe",0);//单位：分
			GoodsUser user  = userService.selectByUserId(userId);
			String couponCode = getParam("couponCode");//优惠码
			/**
			 * 是否含折扣商品 0=不包含 1=包含
			 */
			int useByPercent=getIntParam("useByPercent");
			/**
			 * 是否含预售 0=不包含 1=包含
			 */
			int isPrepay=getIntParam("isPrepay");
			
			ReturnJsonEntity queryValidEntity = couponService.queryValidCoupon(couponCode,user.getMobileNo(),orderJe,useByPercent,isPrepay);
			entity = queryValidEntity;
		}catch(Exception er){
			log.error(er.getMessage());
			status=StatusCodeEnum.CODE100000;
		}
		entity.setCode(status.getCode());
		entity.setMsg(status.getMsg());
		return entity;
	}
	
}
